package com.cskaoyan.controller.marketingmanagement;

import com.cskaoyan.bean.marketingmanagementbean.CouponData;
import com.cskaoyan.bean.marketingmanagementbean.CouponUserData;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketCoupon;
import com.cskaoyan.bean.MarketCouponUser;
import com.cskaoyan.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 创建日期: 2022/05/05 20:15
 *
 * @author liutao
 */

@RestController
@RequestMapping("admin/coupon")
public class CouponController {

    @Autowired
    CouponService couponService;

    @RequestMapping("list")
    public BaseRespVo couponList(BaseParam param, String name, Integer type, Integer status) {
        CouponData couponData = couponService.query(param, name, type, status);
        return BaseRespVo.ok(couponData);
    }

    @RequestMapping("create")
    public BaseRespVo couponCreate(@RequestBody MarketCoupon marketCoupon) {
        marketCoupon.setAddTime(new Date());
        marketCoupon.setUpdateTime(new Date());
        marketCoupon.setDeleted(false);
        couponService.createCoupon(marketCoupon);
        return BaseRespVo.ok(marketCoupon);
    }

    @RequestMapping("update")
    public BaseRespVo couponUpdate(@RequestBody MarketCoupon marketCoupon) {
        marketCoupon.setUpdateTime(new Date());
        couponService.couponUpdate(marketCoupon);
        return BaseRespVo.ok(marketCoupon);
    }

    @RequestMapping("delete")
    public BaseRespVo couponDelete(@RequestBody MarketCoupon marketCoupon) {
        marketCoupon.setDeleted(true);
        couponService.couponDelete(marketCoupon);
        return BaseRespVo.ok(null);
    }

    @RequestMapping("listuser")
    public BaseRespVo listuser(BaseParam baseParam, MarketCouponUser marketCouponUser) {
        CouponUserData couponUserData = couponService.listuser(baseParam, marketCouponUser);
        return BaseRespVo.ok(couponUserData);
    }

    @RequestMapping("read")
    public BaseRespVo couponRead(String id) {
        MarketCoupon marketCoupon = couponService.couponRead(id);
        return BaseRespVo.ok(marketCoupon);
    }

}
